package com.yuncheng.oaApi.config;

import com.yuncheng.oaApi.constant.OaBusinessConstant;
import org.apache.commons.io.FileUtils;
import org.gxfda.sms.client.ISmsClientHelper;
import org.gxfda.sms.client.SmsClientHelperImpl;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;

import java.io.File;
import java.io.IOException;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.spec.InvalidKeySpecException;

/**
 * 短信 配置类
 */
@Configuration
public class OaSmsConfig {

    @Value("${file.path}")
    public String TEMPORARY_UPLOAD_MKDIR_ROOT;

    private PrivateKey privateKey;
    private ISmsClientHelper smsClient;

    /*public SmsConfig() throws NoSuchAlgorithmException, IOException, InvalidKeySpecException {
        String certPath = BusinessConstant.SNED_SMS_FILE_ROOT_URL;
        Resource resource = new ClassPathResource(certPath);
        File file = new File(TEMPORARY_UPLOAD_MKDIR_ROOT+"/"+BusinessConstant.SNED_SMS_FILE_ROOT_URL);
        FileUtils.copyToFile(resource.getInputStream(),file);
        privateKey = SmsClientHelperImpl.readPrivateKey(file.getAbsolutePath());
        smsClient = SmsClientHelperImpl.getInstance("yjj_cyxt", privateKey,
                "http://172.18.0.100/yjjsms/smsapi/v2/send.do");
    }*/

    // 2024-14
    /*public SmsConfig() throws NoSuchAlgorithmException, IOException, InvalidKeySpecException {
        String certPath = BusinessConstant.SNED_SMS_FILE_ROOT_URL;
        Resource resource = new ClassPathResource(certPath);
        File file = new File(TEMPORARY_UPLOAD_MKDIR_ROOT+"/"+BusinessConstant.SNED_SMS_FILE_ROOT_URL);
        FileUtils.copyToFile(resource.getInputStream(),file);
        privateKey = SmsClientHelperImpl.readPrivateKey(file.getAbsolutePath());
        smsClient = SmsClientHelperImpl.getInstance("yjj_cyxt", privateKey,
                "https://172.18.0.100/yjjsms/smsapi/v3/send.do");
    }*/

    public OaSmsConfig() throws NoSuchAlgorithmException, IOException, InvalidKeySpecException {
        String certPath = OaBusinessConstant.SNED_SMS_FILE_ROOT_URL;
        Resource resource = new ClassPathResource(certPath);
        File file = new File(TEMPORARY_UPLOAD_MKDIR_ROOT+"/"+ OaBusinessConstant.SNED_SMS_FILE_ROOT_URL);
        FileUtils.copyToFile(resource.getInputStream(),file);
        privateKey = SmsClientHelperImpl.readPrivateKey(file.getAbsolutePath());
        smsClient = SmsClientHelperImpl.getInstance("yjj_cyxt", privateKey,
                "https://172.18.0.100/yjjsms/smsapi/v3");
    }

    /*public void getSmsMoConfig() throws NoSuchAlgorithmException, IOException, InvalidKeySpecException {
        String certPath = BusinessConstant.SNED_SMS_FILE_ROOT_URL;
        Resource resource = new ClassPathResource(certPath);
        File file = new File(TEMPORARY_UPLOAD_MKDIR_ROOT+"/"+BusinessConstant.SNED_SMS_FILE_ROOT_URL);
        FileUtils.copyToFile(resource.getInputStream(),file);
        privateKey = SmsClientHelperImpl.readPrivateKey(file.getAbsolutePath());
        smsClient = SmsClientHelperImpl.getInstance("yjj_cyxt", privateKey,
                "https://172.18.0.100/yjjsms/smsapi/v3/getMo.do");
    }*/

    public PrivateKey getPrivateKey() {
        return privateKey;
    }

    public void setPrivateKey(PrivateKey privateKey) {
        this.privateKey = privateKey;
    }

    public ISmsClientHelper getSmsClient() {
        return smsClient;
    }

    public void setSmsClient(ISmsClientHelper smsClient) {
        this.smsClient = smsClient;
    }
}
